const { DataTypes } = require('sequelize');
const { sequelize } = require('../utils/database');

const ActivityParticipant = sequelize.define('ActivityParticipant', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  activity_id: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  status: {
    type: DataTypes.ENUM('registered', 'attended', 'cancelled', 'no_show'),
    defaultValue: 'registered'
  },
  registered_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  attended_at: {
    type: DataTypes.DATE,
    allowNull: true
  },
  rating: {
    type: DataTypes.INTEGER,
    allowNull: true,
    validate: {
      min: 1,
      max: 5
    }
  },
  feedback: {
    type: DataTypes.TEXT,
    allowNull: true
  }
}, {
  tableName: 'activity_participants',
  indexes: [
    {
      fields: ['user_id', 'activity_id'],
      unique: true
    },
    {
      fields: ['activity_id']
    },
    {
      fields: ['status']
    }
  ]
});

module.exports = ActivityParticipant; 